package com.wooophone.mpyeah.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.wooophone.mpyeah.dao.RealStoreDao;
import com.wooophone.mpyeah.entity.RealStore;
import com.wooophone.mpyeah.mapper.RealStoreMapper;

public class RealStoreDaoImpl implements RealStoreDao {
	
	@Autowired
	RealStoreMapper realStoreMapper;
	public void setRealStoreMapper(RealStoreMapper realStoreMapper) {
		this.realStoreMapper = realStoreMapper;
	}

	@Override
	public RealStore save(RealStore obj) {
		realStoreMapper.save(obj);
		return obj;
	}

	@Override
	public int update(RealStore obj) {
		return realStoreMapper.update(obj);
	}

	@Override
	public int delete(String id) {
		return realStoreMapper.delete(id);
	}

	@Override
	public RealStore get(String id) {
		return realStoreMapper.get(id);
	}

	@Override
	public List<RealStore> list() {
		return realStoreMapper.list();
	}

	@Override
	public List<RealStore> list(int offset, int limit) {
		Map<String, Object> parameter=new HashMap<String, Object>();
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return realStoreMapper.listByLimit(parameter);
	}

	@Override
	public int count() {
		return realStoreMapper.count();
	}

	@Override
	public List<RealStore> find(Map<String, Object> parameter) {
		return realStoreMapper.listByParameter(parameter);
	}

	@Override
	public List<RealStore> find(Map<String, Object> parameter, int offset, int limit) {
		parameter.put("limit", limit);
		parameter.put("offset", offset);
		return realStoreMapper.listByParameter(parameter);
	}

	@Override
	public int count(Map<String, Object> parameter) {
		return realStoreMapper.countByParameter(parameter);
	}

	@Override
	public int count(String keyword) {
		keyword="%"+keyword+"%";
		Map<String, Object> parameter=new HashMap<String, Object>();
		parameter.put("keyword", keyword);
		return realStoreMapper.countByKeyword(parameter);
	}

	@Override
	public List<RealStore> search(String keyword, int offset, int limit) {
		Map<String, Object> parameter=new HashMap<String, Object>();
		parameter.put("limit", limit);
		parameter.put("offset", offset);
		parameter.put("keyword", "%"+keyword+"%");
		return realStoreMapper.search(parameter);
	}

	public int countByBrandId(String brandId){
		return realStoreMapper.countByBrandId(brandId);
	}
}
